﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace SkinnedModel
{
    public class Containers
    {
        #region Fields

        private AnimationPlayer animationPlayerValue;
        private AnimationClip animationClipValue;
        private String animationClipName;
        private AnimationPlayer.PlaybackMode playbackModeValue;
        private AnimationPlayer.PlaybackStatus playbackStatusValue;
        private int repeatValue;
        private bool crossFadeValue;
        private TimeSpan durationValue;
        private TimeSpan startValue;
        private TimeSpan endValue;
        private float scaleValue;
        private int[] clipMapValue;
        private bool isEnabled;

        #endregion

        /// <summary>
        /// Constructs a new Container object
        /// </summary>
        /// <param name="bone">Bone index</param>
        /// <param name="keyframeIndex">List of keyframe indices</param>
        public Containers(AnimationPlayer animationPlayer, String name, AnimationClip animationClip, AnimationPlayer.PlaybackMode playbackMode)
        {
            animationPlayerValue = animationPlayer;
            animationClipValue = animationClip;
            animationClipName = name;
            playbackModeValue = playbackMode;
            playbackStatusValue = AnimationPlayer.PlaybackStatus.Idle;
            repeatValue = 0;
            crossFadeValue = false;
            durationValue = TimeSpan.Zero;
            startValue = TimeSpan.Zero;
            endValue = TimeSpan.Zero;
            scaleValue = 1.0f;
            clipMapValue = null;
            isEnabled = true;
        }
        /// <summary>
        /// Gets the Animation player.
        /// </summary>
        public AnimationPlayer PlayerInfo
        {
            get { return animationPlayerValue; }
        }

        /// <summary>
        /// Gets/Sets the animation clip for the player
        /// </summary>
        public AnimationClip AnimationClips
        {
            get { return animationClipValue; }
            set { animationClipValue = value; }
        }
        public String AnimationClipName
        {
            get { return animationClipName; }
            set { animationClipName = value; }
        }

        /// <summary>
        /// Gets/Sets the type of playback
        /// </summary>
        public AnimationPlayer.PlaybackMode PlaybackMode
        {
            get { return playbackModeValue; }
            set 
            { 
                playbackModeValue = value;
                if ((value == AnimationPlayer.PlaybackMode.Forward) ||
                    (value == AnimationPlayer.PlaybackMode.Backward))
                    repeatValue = (int)MathHelper.Max(repeatValue*1.0f, 1.0f);
                else
                    repeatValue = 0;
            }
        }

        /// <summary>
        /// Gets/Sets the number of repeat play if playback mode is not looped
        /// </summary>
        public int Repeat
        {
            get { return repeatValue; }
            set 
            {
                if ((playbackModeValue == AnimationPlayer.PlaybackMode.Forward) ||
                    (playbackModeValue == AnimationPlayer.PlaybackMode.Backward))
                    repeatValue = value;
                else
                    repeatValue = 0;
            }
        }

        /// <summary>
        /// Enables/Disables cross fading
        /// </summary>
        public bool CrossFade
        {
            get { return crossFadeValue; }
            set { crossFadeValue = value; }
        }

        /// <summary>
        /// Gets/Sets the crossfade duration
        /// </summary>
        public TimeSpan FadeDuration
        {
            get { return durationValue; }
            set 
            { 
                durationValue = value;
                if (durationValue > TimeSpan.Zero)
                    crossFadeValue = true;
                else
                    crossFadeValue = false;
            }
        }

        /// <summary>
        /// Gets/Sets the players current status
        /// </summary>
        public AnimationPlayer.PlaybackStatus Status
        {
            get { return playbackStatusValue; }
            set { playbackStatusValue = value; }
        }

        public bool IsEnabled
        {
            get { return isEnabled; }
            set { isEnabled = value; }
        }

        public TimeSpan Start
        {
            get { return startValue; }
        }

        public TimeSpan End
        {
            get { return endValue; }
        }

        public float Scale
        {
            get { return scaleValue; }
            set { scaleValue = value; }
        }

        public int[] ClipMap
        {
            get { return clipMapValue; }
            set { clipMapValue = value; }
        }
    }
}
